package net.maku.module.genealogy.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.module.genealogy.convert.GenealogyConvert;
import net.maku.module.genealogy.entity.GenealogyEntity;
import net.maku.module.genealogy.service.GenealogyService;
import net.maku.module.genealogy.vo.GVO;
import net.maku.module.genealogy.vo.GenealogyVO;
import net.maku.newbase.NewBaseController;
import net.maku.newbase.NewQuery;
import net.maku.newbase.PageParam;

import org.springframework.web.bind.annotation.*;

/**
 * 族谱
 *
 * @author
 */
@RestController
@RequestMapping("nb/genealogy")
@Tag(name = "族谱")
@AllArgsConstructor
public class GenealogyController extends NewBaseController<GenealogyService, GenealogyEntity> {

    @GetMapping("page")
    @Operation(summary = "分页")
    public Result<PageResult<GenealogyVO>> page(PageParam page, NewQuery query) {
        LambdaQueryWrapper<GenealogyEntity> select = new LambdaQueryWrapper<>();

        IPage<GenealogyEntity> iPage = entityService.page(page.b(), select);
        return Result.ok(new PageResult<GenealogyVO>(GenealogyConvert.INSTANCE.convertList(iPage.getRecords()), iPage.getTotal()));
    }

    @PostMapping("findData")
    @Operation(summary = "测试")
    public Result<JSONArray> findData() {

        JSONArray jsonArray1 = new JSONArray();
        JSONArray jsonArray2 = new JSONArray();

        jsonArray1.add(new GVO("高祖"));

        jsonArray2.add(new GVO("曾祖姑"));
        jsonArray2.add(new GVO("曾祖"));
        jsonArray2.add(new GVO("曾祖叔祖"));

        JSONArray jsonArray = new JSONArray();

        jsonArray.add(jsonArray1);
        jsonArray.add(jsonArray2);

        return Result.ok(jsonArray);
    }

}